# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=codelite
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=9.2.109.g758c3c4
pkgrel=1
pkgdesc="Open-source, cross platform IDE for the C/C++ programming languages (mingw-w64)"
arch=('any')
license=('GPL')
url="http://www.codelite.org"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-hunspell"
         "${MINGW_PACKAGE_PREFIX}-libssh"
         "${MINGW_PACKAGE_PREFIX}-drmingw"
         "${MINGW_PACKAGE_PREFIX}-wxWidgets"
         )
optdepends=("${MINGW_PACKAGE_PREFIX}-clang")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-clang"
             "git")
options=(strip staticlibs !debug)
source=("${_realname}::git+https://github.com/eranif/codelite.git"
        include-winsock-header.patch
        mingw-use-wx-manifests.patch
        use-gnu-extensions.patch
        windows-headers-conflict.patch
        fix-sqlite3-find-and-build.patch
        clStandardPaths-missing-member.patch
        mingw-posix-layout-fix.patch
        proper-libraries-names-mingw.patch)
sha256sums=('SKIP'
            '049c138e6c24a37a5c42e90fa01b7c8117aaf2265a7e0d92801152ae771ec5d2'
            'bdc8e27060fc4e614fd354c580f7a0d6615763397287912c160eb0285c148473'
            'b4c694cecd603c545262a904621d24d00412a3203e3193e06d382f86faf6d7f6'
            '3e2ef148dd4b84fa5de65cbca9df5992c0424b3694d795daff793cfd1dfe4f28'
            'ad3f971836dca9f723186cc9868ec157bee53858d69b8ab4ee16e92a7bd7d4cb'
            '3c1382c007490c718c77d44e0bf63b0bd32d025b1681e83e94a5632ea92fa832'
            '887671f4985d16a076751f6224784cb6ad28105445fbcbe23a3db5772e109478'
            '1206b6453000e1dbe8058fb646c97599b2a072f4aad412047f439b288e662777')

pkgver() {
  cd "${_realname}"
  git describe --tags | sed 's|-|.|g'
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/include-winsock-header.patch
  patch -p1 -i ${srcdir}/mingw-use-wx-manifests.patch
  patch -p1 -i ${srcdir}/use-gnu-extensions.patch
  patch -p1 -i ${srcdir}/windows-headers-conflict.patch
  patch -p1 -i ${srcdir}/fix-sqlite3-find-and-build.patch
  patch -p1 -i ${srcdir}/clStandardPaths-missing-member.patch
  patch -p1 -i ${srcdir}/mingw-posix-layout-fix.patch
  patch -p1 -i ${srcdir}/proper-libraries-names-mingw.patch
}

package() {
  local -a extra_config

  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}
  #cd ${srcdir}/${_realname}
  ${MINGW_PREFIX}/bin/cmake \
    -Wno-dev \
    -G"MSYS Makefiles" \
    -DPREFIX=${pkgdir}${MINGW_PREFIX} \
    -DENABLE_CLANG=1 \
    -DWITH_WEBVIEW=1 \
    -DwxWidgets_CONFIG_EXECUTABLE=${MINGW_PREFIX}/bin/wx-config \
    -DwxWidgets_wxrc_EXECUTABLE=${MINGW_PREFIX}/bin/wxrc-3.0 \
    "${extra_config[@]}" \
    ../${_realname}

  make # -j1 VERBOSE=1
  make install

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/codelite/*.a
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/*.a
}
